package cn.highedu.spring.bean17;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@ComponentScan("cn.highedu.spring.bean17")
public class TestInfrastructureConfig {

    @Bean
    public DataSource dataSource() {
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false");
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        return dataSource;
    }


    @Bean // 添加一个MyConfigurationCustomizer，用于修改BeanDefinition
    // static方法，返回一个MyConfigurationCustomizer, 它需要在创建任何Bean之前运行
    public static MyConfigurationCustomizer myBeanFactoryPostProcessor() {
        return new MyConfigurationCustomizer();
    }

    @Bean
    public BeanPostProcessor beanPostProcessor(){
        return new CustomBeanPostProcessor();
    }
}
